package com.example.testuser.repository;

import com.example.testuser.entity.TestUser;
import org.aspectj.weaver.ast.Test;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Stream;

@Repository
public interface UserRepository extends JpaRepository<TestUser,String> {

    TestUser findByCodeOrName(String code, String name);

    //@Query("select * from test_User identity = ?1 ", nativeQuery = true)
    @Query("select u from TestUser u where u.identity = ?1 ")
    List<TestUser> findListMySql(String identity);

    @Query(value = "select * from test_user ",nativeQuery = true)
    Stream<?> streamAllUsers();

    @Query(value = "select u from TestUser u ")
    Stream<TestUser> streamAllUsers1();

    Stream<TestUser> streamAllBy();

    @Async
    CompletableFuture<List<TestUser>> readAllBy();

}
